*****Figure 4a Coefficients*****

use "PartySupport_MASTER.dta"

set more off 

gen AbsNominate=abs(nominate_dim1)
gen VoteShare_lag=dv_lag if party_code==100
replace VoteShare_lag=100-dv_lag if party_code==200
gen presvote=dpres if party_code==100
replace presvote=100-dpres if party_code==200

egen distgroup=group(state_abbrev district_code)

*VOTETYPES
*Regular Passage Category
gen RegPass=1 if VoteType==11 | VoteType==12 | VoteType==14 | VoteType==30
replace RegPass=0 if RegPass==.
label var RegPass "Regular Passage Category, VoteType types 11, 12, 14, 30"
*Suspensions Category
gen Susp=1 if VoteType==15 | VoteType==16 | VoteType==33 | VoteType==68
replace Susp=0 if Susp==.
label var Susp "Suspension Category, VoteType types 15, 16, 33, 68"
*Other Passage Category
gen OtherPass= 1 if VoteType==1 | VoteType==13 | VoteType==17 | VoteType==18 | VoteType==19 | VoteType==31 | VoteType==32
replace OtherPass=0 if OtherPass==.
label var OtherPass "Other Passage Category, VoteType types 1, 13, 17, 18, 19, 31, 32"
*Amendments Category
gen Amend=1 if VoteType==21 | VoteType==22 | VoteType==23 | VoteType==24 | VoteType==25 | VoteType==26 | VoteType==27 | VoteType==28 | VoteType==29 | VoteType==80
replace Amend=0 if Amend==.
label var Amend "Amendments Category, VoteType types 21, 22, 23, 24, 25, 26, 27, 28, 29, 80"
*Procedural Partisan Category
gen ProPart=1 if VoteType==61 | VoteType==76 | VoteType==77 | VoteType==79 | VoteType==81 | VoteType==82 | VoteType==88 | VoteType==89 | VoteType==93 | VoteType==95 | VoteType==97 | VoteType==99
replace ProPart=0 if ProPart==.
label var ProPart "Procedural Partisan Category, VoteType types 61, 76, 77, 79, 81, 82, 88, 89, 93, 95, 97, 99"
*Miscellaneous Procedural Category
gen MiscPro=1 if RegPass==0 & Susp==0 & OtherPass==0 & Amend==0 & ProPart==0
replace MiscPro=0 if MiscPro==.
label var MiscPro "Miscellaneous Procedural Category, VoteType types: All others"

matrix mat1=J(9, 4, .)

*For less than or equal to 50
forvalues i=10(5)50 {
_pctile presvote, p(`i')
return list
gen percentile`i'=r(r1)
logit PartyUnityVote c.DaysToElection##c.Cycle DaysToElection2 DaysToElection3 if PresPartyUnity==1 & presvote<=percentile`i', vce(cluster distgroup)
scalar b`i'=_b[c.DaysToElection#c.Cycle]
scalar se`i'=_se[c.DaysToElection#c.Cycle]
scalar t`i'=b`i'/se`i'
scalar n`i'=e(N)-e(df_m)
scalar p`i'=2*ttail(n`i', abs(t`i'))
}

matrix mat1[1,1]=b10
matrix mat1[1,2]=se10
matrix mat1[1,3]=t10
matrix mat1[1,4]=p10
matrix mat1[2,1]=b15
matrix mat1[2,2]=se15
matrix mat1[2,3]=t15
matrix mat1[2,4]=p15
matrix mat1[3,1]=b20
matrix mat1[3,2]=se20
matrix mat1[3,3]=t20
matrix mat1[3,4]=p20
matrix mat1[4,1]=b25
matrix mat1[4,2]=se25
matrix mat1[4,3]=t25
matrix mat1[4,4]=p25
matrix mat1[5,1]=b30
matrix mat1[5,2]=se30
matrix mat1[5,3]=t30
matrix mat1[5,4]=p30
matrix mat1[6,1]=b35
matrix mat1[6,2]=se35
matrix mat1[6,3]=t35
matrix mat1[6,4]=p35
matrix mat1[7,1]=b40
matrix mat1[7,2]=se40
matrix mat1[7,3]=t40
matrix mat1[7,4]=p40
matrix mat1[8,1]=b45
matrix mat1[8,2]=se45
matrix mat1[8,3]=t45
matrix mat1[8,4]=p45
matrix mat1[9,1]=b50
matrix mat1[9,2]=se50
matrix mat1[9,3]=t50
matrix mat1[9,4]=p50

matlist mat1

*             |        c1         c2         c3         c4 
*-------------+--------------------------------------------
*          r1 | -3.36e-06   5.50e-06   -.611649   .5407703 
*          r2 | -6.78e-06   4.32e-06  -1.570719   .1162482 
*          r3 | -7.44e-06   3.79e-06  -1.963308   .0496107 
*          r4 | -8.77e-06   3.27e-06  -2.680463   .0073521 
*          r5 | -9.58e-06   3.01e-06  -3.183584   .0014547 
*          r6 |  -.000011   2.89e-06  -3.803701   .0001426 
*          r7 | -.0000118   2.65e-06  -4.449998   8.59e-06 
*          r8 | -.0000123   2.43e-06  -5.033287   4.82e-07 
*          r9 | -.0000121   2.26e-06  -5.356398   8.49e-08 


matrix mat1b=J(1, 4, .)

*For greater than 50
_pctile presvote, p(50)
return list
gen percentile50b=r(r1)
logit PartyUnityVote c.DaysToElection##c.Cycle DaysToElection2 DaysToElection3 if PresPartyUnity==1 & presvote>percentile50b, vce(cluster distgroup)
scalar b50=_b[c.DaysToElection#c.Cycle]
scalar se50=_se[c.DaysToElection#c.Cycle]
scalar t50=b50/se50
scalar n50=e(N)-e(df_m)
scalar p50=2*ttail(n50, abs(t50))

matrix mat1b[1,1]=b50
matrix mat1b[1,2]=se50
matrix mat1b[1,3]=t50
matrix mat1b[1,4]=p50

matlist mat1b

*             |        c1         c2         c3         c4 
*-------------+--------------------------------------------
*          r1 | -.0000131   2.02e-06  -6.473595   9.57e-11 


drop percentile10-percentile50b



*****Figure 4b Coefficients*****

gen post1994elec=1 if Cycle>=21
replace post1994elec=0 if post1994elec==.

matrix mat2=J(9, 4, .)

*For less than or equal to 50
forvalues i=10(5)50 {
_pctile presvote, p(`i')
return list
gen percentile`i'=r(r1)
logit PartyUnityVote c.DaysToElection##i.post1994elec DaysToElection2 DaysToElection3 if PresPartyUnity==1 & presvote<=percentile`i', vce(cluster distgroup)
matrix A`i'=r(table)
scalar b`i'=A`i'[1,5]
scalar se`i'=A`i'[2,5]
scalar t`i'=b`i'/se`i'
scalar n`i'=e(N)-e(df_m)
scalar p`i'=2*ttail(n`i', abs(t`i'))
}

matrix mat2[1,1]=b10
matrix mat2[1,2]=se10
matrix mat2[1,3]=t10
matrix mat2[1,4]=p10
matrix mat2[2,1]=b15
matrix mat2[2,2]=se15
matrix mat2[2,3]=t15
matrix mat2[2,4]=p15
matrix mat2[3,1]=b20
matrix mat2[3,2]=se20
matrix mat2[3,3]=t20
matrix mat2[3,4]=p20
matrix mat2[4,1]=b25
matrix mat2[4,2]=se25
matrix mat2[4,3]=t25
matrix mat2[4,4]=p25
matrix mat2[5,1]=b30
matrix mat2[5,2]=se30
matrix mat2[5,3]=t30
matrix mat2[5,4]=p30
matrix mat2[6,1]=b35
matrix mat2[6,2]=se35
matrix mat2[6,3]=t35
matrix mat2[6,4]=p35
matrix mat2[7,1]=b40
matrix mat2[7,2]=se40
matrix mat2[7,3]=t40
matrix mat2[7,4]=p40
matrix mat2[8,1]=b45
matrix mat2[8,2]=se45
matrix mat2[8,3]=t45
matrix mat2[8,4]=p45
matrix mat2[9,1]=b50
matrix mat2[9,2]=se50
matrix mat2[9,3]=t50
matrix mat2[9,4]=p50

matlist mat2


*             |        c1         c2         c3         c4 
*-------------+--------------------------------------------
*          r1 |  .0002371   .0001027   2.308657    .020963 
*          r2 |  .0001804   .0000747   2.415056    .015733 
*          r3 |  .0001223   .0000625   1.955107   .0505706 
*          r4 |  .0000851     .00006   1.417296   .1563967 
*          r5 |  .0000634    .000055   1.153177   .2488379 
*          r6 |  .0000216   .0000518   .4164541   .6770778 
*          r7 | -3.59e-07   .0000479  -.0074834   .9940291 
*          r8 | -.0000112   .0000439  -.2548438   .7988438 
*          r9 | -.0000144   .0000433   -.333652   .7386422 

matrix mat2b=J(1, 4, .)

*For greater than 50
_pctile presvote, p(50)
return list
gen percentile50b=r(r1)
logit PartyUnityVote c.DaysToElection##i.post1994elec DaysToElection2 DaysToElection3 if PresPartyUnity==1 & presvote>percentile50b, vce(cluster distgroup)
matrix A50=r(table)
scalar b50=A50[1,5]
scalar se50=A50[2,5]
scalar t50=b50/se50
scalar n50=e(N)-e(df_m)
scalar p50=2*ttail(n50, abs(t50))


matrix mat2b[1,1]=b50
matrix mat2b[1,2]=se50
matrix mat2b[1,3]=t50
matrix mat2b[1,4]=p50

matlist mat2b

*             |        c1         c2         c3         c4 
*-------------+--------------------------------------------
*          r1 | -.0001877   .0000409  -4.584366   4.55e-06 


clear

*Store matrices

svmat double mat1
svmat double mat1b
set obs 10
replace mat11=mat1b1[1] if mat11==.
replace mat12=mat1b2[1] if mat12==.
replace mat13=mat1b3[1] if mat13==.
replace mat14=mat1b4[1] if mat14==.
drop mat1b1-mat1b4
rename mat11 coef
rename mat12 se
rename mat13 t
rename mat14 p
gen counter=_n
gen percentile=(counter+1)*5 if counter<10
replace percentile=counter*5 if counter>=10
move counter coef
move percentile coef
save "Figure4aData.dta"

clear

svmat double mat2
svmat double mat2b
set obs 10
replace mat21=mat2b1[1] if mat21==.
replace mat22=mat2b2[1] if mat22==.
replace mat23=mat2b3[1] if mat23==.
replace mat24=mat2b4[1] if mat24==.
drop mat2b1-mat2b4
rename mat21 coef
rename mat22 se
rename mat23 t
rename mat24 p
gen counter=_n
gen percentile=(counter+1)*5 if counter<10
replace percentile=counter*5 if counter>=10
move counter coef
move percentile coef
save "Figure4bData.dta"


clear
